package com.sky.controller.admin;


import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminCategoryController")
@Slf4j
@RequestMapping("/admin/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 新增分类
     * @param categoryDTO
     * @return
     */
    @PostMapping
    public Result addCategory(@RequestBody CategoryDTO categoryDTO){
        return categoryService.addCategory(categoryDTO);
    }

    /**
     * 分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result page(CategoryPageQueryDTO categoryPageQueryDTO){
        return categoryService.pageCategory(categoryPageQueryDTO);
    }

    /**
     * 根据id删除分类
     * @param id
     * @return
     */
    @DeleteMapping
    public Result deleteCategory(Long id){
        return categoryService.deleteCategory(id);
    }

    /**
     * 修改分类
     * @param category
     * @return
     */
    @PutMapping
    public Result updateCategory(@RequestBody Category category){
        return categoryService.updateCategory(category);
    }

    /**
     * 启动/禁用分类
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status,Long id){
        return categoryService.updateStatus(status,id);
    }

    /**
     * 按照类型查找
     * @param type
     * @return
     */
    @GetMapping("/list")
    public Result<List<Category>> selectType(Integer type){
        List<Category> list = categoryService.selectType(type);
//        return categoryService.selectType(type);
        return Result.success(list);
    }
}
